# coding=utf-8
import traceback

import pymysql.cursors

from tests.modules.ucloud.servers import servers
from tests.modules.ucloud.ucloud_db import UcloudApp


def deal_all_db():
    for ser in servers:
        _ip = ser

        uc = UcloudApp(ip=_ip)

        try:

            uc.do_insert(app_name='upush2-push-office',
                         zone='uc.gzidc.area',
                         zone_alias='gzidc',
                         port=6160,
                         app_type='spring-boot',
                         db_name='upush2',
                         mem_level=1,
                         db_type='mysql')

            uc.commit()

            uc.do_insert(app_name='upush2-send-center',
                         zone='uc.gzidc.area',
                         zone_alias='gzidc',
                         port=6170,
                         app_type='spring-boot',
                         db_name=None,
                         mem_level=1,
                         )

            uc.commit()

            uc.do_insert(app_name='upush2-contact-sync',
                         zone='uc.gzidc.area',
                         zone_alias='gzidc',
                         port=6180,
                         app_type='spring-boot',
                         db_name=None,
                         mem_level=1)

            uc.commit()

            uc.do_insert(app_name='upush2-transport-dubbo',
                         zone='uc.gzidc.area',
                         zone_alias='gzidc',
                         port=6190,
                         app_type='spring-boot',
                         db_name=None,
                         mem_level=1)

            uc.commit()

            uc.do_insert(app_name='upush2-console-ui',
                         zone='uc.gzidc.area',
                         zone_alias='gzidc',
                         port=880,
                         app_type='php',
                         db_name=None,
                         mem_level=1)

            uc.commit()

        except BaseException, ex:
            print ex.message

        finally:

            uc.close()


deal_all_db()
